`timescale 1ns / 10ps
//    ********************** НАЧАЛО МОДУЛЯ *********************************************************
module ModImpulseFormer
    #(  parameter freq_p        = 10_000_000,
        parameter up_ns_p       = 100,
        parameter period_ns_p   = 500,
        parameter phase_p       = 500
    )
    (   input  logic            reset_n,
        input  logic            clk,
        
        output logic            impulse
    );

//    ********************* КОНСТАНТЫ **************************************************************
    localparam longint up_lp        = up_ns_p      * freq_p / 1_000_000_000;
    localparam longint period_lp    = period_ns_p  * freq_p / 1_000_000_000;
    localparam longint phase_lp     = (period_ns_p * phase_p/ 360) * freq_p / 1_000_000_000;

    //    ********************* СОЗДАНИЕ И ОПИСАНИЕ ПЕРЕМЕННЫХ *****************************************
    
    logic [31:0]    time_cnt;
//  ********************* БЛОК НЕПРЕРЫВНЫХ НАЗНАЧЕНИЙ ASSIGN ***************************************

    initial time_cnt = 0;
//  ********************* ОПИСАНИЕ ПРОЦЕССОВ *******************************************************

    always_ff @(posedge clk, negedge reset_n)
    begin
        if (!reset_n) begin         // Сброс по ресету
            impulse     <= 1'b0;
            time_cnt    <= 32'd0;
        end 
        else  begin
            time_cnt    <= time_cnt + 32'd1;
            impulse     <= 1'b0;
            if (time_cnt < phase_lp)
                ;
            else if (time_cnt <= (up_lp + phase_lp))
                impulse  <= 1'b1;
            else if (time_cnt >= period_lp) begin
                time_cnt <= 32'd0;
            end
            else;
        end
    end
endmodule